<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of personal_model
 *
 * @author Neil
 */
class habitacion_model extends CI_Model {

    public function Habitacion() {
        $query = $this->db->query('SELECT id_habi, nro_habi, desc_tipo, piso FROM habitacion h INNER JOIN tipo_habitacion t ON h.tipo_habi = t.id_tipo ORDER BY h.id_habi');
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data[] = null;
        }
        return $data;
    }

    public function controlHabitacion() {
        $fecha = date("Y/m/d");
        $query = $this->db->query('select * from reserva where est_res=1 and fec_res=?', $fecha);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila1) :
                $data[] = $fila1;
            endforeach;
        }else {
            $data = "";
        }
        return $data;
    }
     public function controlHabitacionRegistro() {
       
        $query = $this->db->query('select * from registro where est_reg=1');
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila1) :
                $data[] = $fila1;
            endforeach;
        }else {
            $data = "";
        }
        return $data;
    }
         public function controlHabitacionxFecha($fecha) {
       
        $query = $this->db->query('select * from reserva where est_res=1 and fec_res=?', $fecha);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila1) :
                $data[] = $fila1;
            endforeach;
        }else {
            $data = "";
        }
        return $data;
    }
    public function regMod($codigo, $data) {
        if ($codigo == '') {
            $this->db->insert('habitacion', $data);
        } else {
            $this->db->where('id_habi', $codigo);
            $this->db->update('habitacion', $data);
        }
    }

    public function listarxCod($cod) {
        $query = $this->db->query('SELECT * FROM habitacion where id_habi=?', $cod);
        return $query->result();
    }

    public function tiposHabitacion() {
        $query = $this->db->query('select id_tipo as codigo, desc_tipo as descripcion from tipo_habitacion');
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }
        return $data;
    }

}

?>